package exsun.jt808.data.kafka_data;

import exsun.jt808.data.base.MsgDirection;
import exsun.jt808.data.distribute_data.DistributeEntity;
import exsun.jt808.data.upload_data.Jt808EntityBase;
import exsun.jt808.data.util.GsonUtils;
import exsun.jt808.data.util.HostUtil;
import lombok.Data;

import java.util.Date;

/**
 * @Description: kafka数据包
 */
@Data
public class KafkaJT808Data<T> extends KafkaDataBase<T>{
    /**
     * 设备id
     */
    public  String devNo;

    MsgDirection direction;

    public void KafkaJT808Data(String devNo, int msgId, String topic, T object, MsgDirection direction,int port){
        this.devNo = devNo;
        this.msgId = msgId;
        this.topic = topic;
        this.object = object;
        this.hostName = HostUtil.localHost + ":" + port;
        this.direction = direction;
        this.date = new Date();
    }

    public KafkaJT808Data(DistributeEntity data, MsgDirection direction, T object,int port){
        KafkaJT808Data(data.devNo,data.msgId,data.distributeMsgTopic,object,direction,port);
    }

    public KafkaJT808Data(T data, String devNo,int msgId, String topic, MsgDirection direction,int port){
        KafkaJT808Data(devNo,msgId,topic,data,direction,port);
    }
    public KafkaJT808Data(Jt808EntityBase data, MsgDirection direction, T object,int port){
        KafkaJT808Data(data.dvo,data.mid,data.tpc,object,direction,port);
    }

    public String getJsonFromObject(){
        return GsonUtils.getJsonFromObject(this);
    }


}
